<template>
	<view style="min-height: 100vh;padding-bottom:200rpx">
		<u-navbar title='门店验收' titleStyle="{'color':white}" :autoBack="true" bgColor="transparent"
			:placeholder="false"></u-navbar>
		<image src="https://renovationcdn.jiachuangnet.com/addMaterial/bg.png" style="width:750rpx;height: 664rpx;">
		</image>
		<view :class="['container',current==1?'container_h1':'',current==2?'container_h2':'']">
			<view v-show="current == 0">
				<view style='color:white;margin-bottom:20rpx;border:none'>第一步 基础信息填写</view>
				<view class="flex alignItem bewteen">
					<view class="label label_1">店名名称</view>
					<view class="val">
						<u-input v-model="formData.assignName" :disabled="true" placeholder="店名名称"
							inputAlign="right"></u-input>
					</view>
				</view>
				<view class="flex alignItem bewteen">
					<view class="label label_1">监理</view>
					<view class="val val_1">
						<u-input v-model="formData.chargeUserName" :disabled="true" placeholder="监理"
							inputAlign="right"></u-input>
					</view>
				</view>
				<view class="flex alignItem bewteen">
					<view class="label label_1">装修完工日期</view>
					<view class="val val_1" style="width: 100rpx;">
						<uni-datetime-picker type="date" v-if="evaluateId?false:true" :clear-icon="false"
							@change="changeTimeFn" v-model.sync="formData.decorationStartDate"
							@click.native="showTimePickerFn" @maskClick="maskClick" />
						<u-input v-model="formData.endTime " v-else :disabled="disable"
							inputAlign="right"></u-input>
					</view>
				</view>
				<view class="flex alignItem bewteen">
					<view class="label" style="width: inherit;">装修公司</view>
					<view class="val val_1" style="flex: 1;">
						<u-input v-model="formData.companyName" :disabled="true" placeholder="装修公司"
							inputAlign="right"></u-input>
					</view>
				</view>
				<!-- <view class="flex alignItem bewteen">
					<view class="label label_1">经理</view>
					<view class="val val_1">
						<u-input v-model="formData.projectUserName" :disabled="true" placeholder="经理" inputAlign="right"></u-input>
					</view>
				</view> -->
				<!-- <view class="flex alignItem bewteen">
					<view class="label label_1">售后人员</view>
					<view class="val val_1">
						<u-input v-model="formData.afterName" :disabled="true" placeholder="售后人员" inputAlign="right"></u-input>
					</view>
				</view> -->
				<view v-if="false" class="flex alignItem bewteen">
					<view class="label label_1">指派人</view>
					<view class="val val_1">
						<u-input v-model="formData.userName" :disabled="true" placeholder="指派人"
							inputAlign="right"></u-input>
					</view>
				</view>
				<!-- <view class="flex alignItem bewteen">
					<view class="label label_1">货架公司</view>
					<view class="val val_1">
						<u-input v-model="formData.shelfCompany" :disabled="disable" placeholder="货架公司" inputAlign="right"></u-input>
					</view>
				</view>
				<view class="flex alignItem bewteen">
					<view class="label label_1">监控公司</view>
					<view class="val val_1" >
						<u-input v-model="formData.monitoringCompany" :disabled="disable" placeholder="监控公司" inputAlign="right"></u-input>
					</view>
				</view> -->
				<!-- <view class="flex alignItem bewteen">
					<view class="label label_1">货架配送日期</view>
					<view class="val val_1" style="width: 100rpx;">
						<uni-datetime-picker type="date" v-if="evaluateId?false:true" :clear-icon="false"
							@change="changeTimeFn" @click.native="showTimePickerFn"
							v-model.sync="formData.shelfDeliveryDate" @maskClick="maskClick" />
						<u-input v-else v-model="formData.shelfDeliveryDate" :disabled="disable"
							inputAlign="right"></u-input>
					</view>
				</view> -->
			</view>
			<view v-show="current == 1">
				<!-- <view style='color:white;margin-bottom:20rpx;border:none'>第二步 监理验收</view> -->
				<view style='color:white;margin-bottom:20rpx;border:none'>第二步 监理验收</view>
				<view style="width: 100%;height: 50vh;" v-if="concealedList.length===0">
					<u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" width="100%" height="100%">
					</u-empty>
				</view>
				<template v-for="(item,index) in concealedList">
					<view v-if="item.isShow !== 1" :class="[index===0?'tack_item_0':''] " style="position: relative;"
						:key="item.concealedId">
						
						<view @click="showNowFinishi(item)" v-if="item.isFinish === '未完成' || item.isFinish === '已验收'" style="position: absolute;width: 100%;height: 100%;z-index: 2;opacity: .5;"></view>
						
						<view style='margin-bottom:20rpx;border:none'>{{`${index+1}: ${item.concealedName}`}} <text style="color: red; font-size: 24rpx;" v-if="item.isFinish === '未完成' ||  item.isFinish === '已验收'">{{item.isFinish}}</text> </view>
						<upload :name="index" @uploadFile="uploadFileConcealed"
						sourceType="['camera']"
							:fileListInit="concealedList[index].concealedScorePicture"
							:disabled="evaluateId?true:false">
					
						</upload>
						
						<template v-if=" concealedList[index].images && concealedList[index].images.length">
							<view style='margin-bottom:20rpx;border:none;color: red;margin-top: 10rpx;'>整改图片</view>
							<upload v-if="concealedList[index].images && concealedList[index].images.length" :name="index"
								:fileListInit="concealedList[index].images"
								:maxCount="0"
								:disabled="false" :deletable="false">
							
							</upload>
						</template>
						
						<view class="input_item" v-if="concealedList[index].flag === 2">
							<view style="padding-top: 12rpx;">备注:</view>
							<u--textarea v-model="concealedList[index].concealedRemark"
								:disabled="evaluateId?true:false" placeholder="请输入备注" border="surround" count></u--textarea>
						</view>
						<!-- <view class="input_item">
							<view style="padding-top: 9rpx;">评分（分） </view>
								<u-input type="number" maxlength="3" v-model="concealedEvaluateList[index].concealedScore"
													:disabled="evaluateId?true:false" placeholder="请输入评分"></u-input>
						</view> -->
						
						<template v-if="index !== concealedList.length - 1">
							<view class="input_item" style="justify-content: space-between; width: 400rpx;">
								<view style="padding-top: 9rpx;margin-right: 10rpx;">是否合格:</text>
								</view>
								<uni-data-select :textColor="concealedList[index].flag === 2 ? 'red' : '#333'" style="width: 250rpx;" v-model="concealedList[index].flag" 
									:localdata="flagList" ></uni-data-select>
							</view>
						</template>
						
					</view>
				</template>
				
				<view class="">
					<view style='margin-bottom:20rpx;border:none'>{{`${concealedList.length+1}: 验收任务总评分`}}</view>
					<u-slider activeColor="#13989A" showValue v-model="supervisionScore"></u-slider>
				</view>
			</view>
			<view v-show="current == 2 && (brandPartyId !== 1 && brandPartyId !== 3)">
				<view style='color:white;margin-bottom:20rpx;border:none'>第三步 装修部分验收</view>
				<u-collapse :border="false">
					<u-collapse-item v-for="(item,index) in evaluateList" :key="index" :title="item.name" :name="index">
						<view :class="['tack_item',index2===0?'tack_item_0':''] " v-for="(item2,index2) in item.task"
							:key="index2">
							<view style='margin-bottom:20rpx;border:none'>{{`任务${index2+1}: ${item2.taskName}`}}</view>
							<!-- <u-upload
								:fileList="picMsg[item2.index]"
								@afterRead="afterRead"
								@delete="deletePic"
								:name="item2.index"
								multiple
								:maxCount="10"
							></u-upload> -->
							<upload :name="item2.index" @uploadFile="uploadFileFn"
								:fileListInit="taskListEvaluationForm[item2.index].picture"
								:disabled="evaluateId?true:false">

							</upload>
							<view class="input_item">
								<view style="padding-top: 12rpx;">备注:</view>
								<u--textarea v-model="taskListEvaluationForm[item2.index].remark"
									:disabled="evaluateId?true:false" placeholder="请输入备注" border="surround"
									count></u--textarea>
							</view>
						</view>
					</u-collapse-item>
				</u-collapse>
				<!-- 总评分 移至第二步监理验收 -->
				<view class="input_item"  v-if="false">
					<view style="padding-top: 9rpx;">工程监理评分（分） </view>
					<u-input type="number" maxlength="3" v-model="supervisionScore" :disabled="evaluateId?true:false"
						placeholder="请输入评分"></u-input>
				</view>
				<!-- <view v-for="(item,index) in evaluateList" :key="index">
					<view class="day_num" style="color: #25b0dd;">
						{{item.name}}
					</view>
					<view class="tack_item" v-for="(item2,index2) in item.task" :key="index2">
						<view style='margin-bottom:20rpx;border:none'>{{`任务${index2+1}: ${item2.taskName}`}}</view>
						<u-upload
								:fileList="fileList1"
								@afterRead="afterRead"
								@delete="deletePic"
								name="1"
								multiple
								:maxCount="10"
							></u-upload>
						<view class="input_item">
							<view style="padding-top: 9rpx;">备注:</view>
							<u--textarea v-model="reason" placeholder="请输入备注" border="surround" count ></u--textarea>
						</view>
					</view>
				</view> -->
			</view>
			<!-- <view v-show="current == 3">
				<view style='color:white;margin-bottom:20rpx;border:none'>第四步 货架部分验收</view>
				<view class="tack_item tack_item_0">
					<view style='margin-bottom:20rpx;border:none'>货架</view>
						<upload
						:name="shelf"
						@uploadFile="uploadFileShelf"
						:fileListInit="shelfScorePicture"
						:disabled="evaluateId?true:false"
						>
							
						</upload>
					<view class="input_item">
						<view style="padding-top: 12rpx;">备注:</view>
						<u--textarea v-model="shelfRemark" :disabled="evaluateId?true:false" placeholder="请输入备注" border="surround" count ></u--textarea>
					</view>
					<view class="input_item">
						<view style="padding-top: 9rpx;">工程监理评分（分） </view>
						<u-input type="number"  maxlength="3" v-model="shelfScore" :disabled="evaluateId?true:false" placeholder="请输入评分" ></u-input>
					</view>
				</view>
			</view> -->
			<view v-show="current == 3">
				<view style='color:white;margin-bottom:20rpx;border:none'>第四步 监控部分验收</view>
				<view class="tack_item tack_item_0">
					<view style='margin-bottom:20rpx;border:none'>监控</view>
					<upload :name="shelf" @uploadFile="uploadFileMonitor" :fileListInit="monitoringScorePicture"
						:disabled="evaluateId?true:false">

					</upload>
					<view class="input_item">
						<view style="padding-top: 12rpx;">备注:</view>
						<u--textarea v-model="monitoringRemark" :disabled="evaluateId?true:false" placeholder="请输入备注"
							border="surround" count></u--textarea>
					</view>
					<view class="input_item">
						<view style="padding-top: 9rpx;">工程监理评分（分） </view>
						<u-input type="number" maxlength="3" v-model="monitoringScore" :disabled="evaluateId?true:false"
							placeholder="请输入评分"></u-input>
					</view>
				</view>
			</view>
			<view v-show="current == 4">
				<view style='color:white;margin-bottom:20rpx;border:none'>第{{ brandPartyId !== 1 && brandPartyId !== 3? "三" : "五"}}步 其他</view>
				<u--textarea v-model="remark" :disabled="evaluateId?true:false" placeholder="补充说明栏目" border="surround"
					count></u--textarea>
				<!-- <u-collapse
				    @change="change"
				  >
				    <u-collapse-item
				      title="加盟商评分"
				      name="0"
				    >
				     <view class="flex alignItem bewteen">
				     	<view class="label label_1">装饰得分（分）</view>
				     	<view class="val val_1">
				     		<u-input type="number"  maxlength="3" v-model="franchiseScore.decorationScore" :disabled="evaluateId?true:false" placeholder="满分 100" inputAlign="right"></u-input>
				     	</view>
				     </view>
					 <view class="flex alignItem bewteen">
					 	<view class="label label_1">货架得分（分）</view>
					 	<view class="val val_1">
					 		<u-input type="number"  maxlength="3" v-model="franchiseScore.shelfScore" :disabled="evaluateId?true:false" placeholder="满分 100" inputAlign="right"></u-input>
					 	</view>
					 </view>
					 <view class="flex alignItem bewteen">
					 	<view class="label label_1">监控得分（分）</view>
					 	<view class="val val_1">
					 		<u-input type="number"  maxlength="3" v-model="franchiseScore.monitoringScore" :disabled="evaluateId?true:false" placeholder="满分 100" inputAlign="right"></u-input>
					 	</view>
					 </view>
				    </u-collapse-item>
				  </u-collapse> -->
				<view>签名</view>
				<image v-if="evaluateId" :src="picture"></image>
				<view v-show="!evaluateId" class="signtrue">
					<signtrue @getSignImg='getSignImg'></signtrue>
				</view>
			</view>
		</view>
		<view v-if="current == 0&&isBtnShow" class="bottom" :style="{paddingBottom: bottom+'px'}"
			style="padding:0 50rpx;padding-top: 20rpx">
			<u-button custom-style="height:88rpx;" shape="circle" :color='color'
				@click='current = 1'>下一步，监理验收</u-button>
		</view>
		<view v-if="current == 1" class="bottom flex alignItem" :style="{paddingBottom: bottom+'px'}"
			style="justify-content: center;">
			<view class="bottomleft flex" style="justify-content: center;" @click='current = 0'>
				上一步
			</view>
			<view class="bottomright" @click='skipStep'> {{ (brandPartyId !== 1 && brandPartyId !== 3) ? '下一步，装修部分验收': "下一步，签名" }}</view>
		</view>
		<view v-if="current == 2 && (brandPartyId !==1 && brandPartyId !== 3) " class="bottom flex alignItem"
			:style="{paddingBottom: bottom+'px'}" style="justify-content: center;">
			<view class="bottomleft flex" style="justify-content: center;" @click='current = 1'>
				上一步
			</view>
			<view class="bottomright" @click='current = 3'>
				下一步，监控部分验收</view>
		</view>
		<view v-if="current == 3 && (brandPartyId !==1 && brandPartyId !== 3)" class="bottom flex alignItem"
			:style="{paddingBottom: bottom+'px'}" style="justify-content: center;">
			<view class="bottomleft flex" style="justify-content: center;" @click='current = 2'>
				上一步
			</view>
			<view class="bottomright" @click='current = 4'>
				下一步，其他</view>
		</view>
		<!-- <view v-if="current == 4" class="bottom flex alignItem" :style="{paddingBottom: bottom+'px'}"
			style="justify-content: center;">
			<view class="bottomleft flex" style="justify-content: center;" @click='current = 3'>
				上一步
			</view>
			<view class="bottomright" @click='current = 5'>
				下一步，其他</view>
		</view> -->

		<view v-if="current == 4&&evaluateId" class="bottom" :style="{paddingBottom: bottom+'px'}"
			style="padding:0 50rpx;padding-top: 20rpx">
			<u-button custom-style="height:88rpx;" shape="circle" :color='color' @click='current = 3'>上一步</u-button>
		</view>
		<view v-if="current == 4&&!evaluateId" class="bottom flex alignItem" :style="{paddingBottom: bottom+'px'}"
			style="justify-content: center;">
			<view class="bottomleft flex" style="justify-content: center;border-bottom-right-radius: 80rpx;border-top-right-radius: 80rpx;" @click='backStep'>
				上一步
			</view>
			<view v-if="false" class="bottomright" @click='addEvaluate(0)'>
				保存验收记录</view>
			<view class="bottomright1" @click='updateConfirm'>
				确认验收</view>
		</view>
		<u-calendar minDate="2024-01-01" maxDate="2024-12-01" :show="show" @close="show=false"
			@confirm="confirmTime"></u-calendar>
	</view>
</template>
<script>
	const d = new Date()
	const year = d.getFullYear()
	let month = d.getMonth() + 1
	month = month < 10 ? `0${month}` : month
	const date = d.getDate()
	import Decimal from 'decimal.js'
	import signtrue from '@/components/signtrue/index.vue';
	import upload from "@/components/upload/upload.vue"


	let app = getApp();
	export default {
		data() {
			return {
				unfinished:false,
				finallyConcealedEvaluateList:[],
				single: '',
				minDate: `${year-1}-${month}-${date}`,
				maxDate: `${year+1}-${month}-${date}`,
				brandPartyId: uni.getStorageSync('brandPartyId'),
				concealedEvaluateList: [],
				evaluateId: '',
				taskListEvaluationForm: {},
				show: false,
				evaluateList: [],
				fileList: [],
				flagList: [
					{ value: 1, text: "合格" },
					{ value: 2, text: "不合格" },
				] , // 状态
				reason: '',
				bottom: app.globalData.safeBottom,
				color: app.globalData.defaultColor,
				current: 0,
				remark: '',
				picture: '',
				taskId: 0,
				franchiseScore: {
					decorationScore: '',
					shelfScore: '',
					monitoringScore: ''
				},
				supervisionScore: 0,
				formData: {
					assignName: '', //门店名称
					chargeUserName: '', //监理
					decorationStartDate: null,
					companyName: '', //装修公司
					projectUserName: '', //经理
					shelfDeliveryDate: null,
					afterName: '', //售后人员
					userName: '' //指派人
				},
				isEchoNewMsg:false,
				shelfScorePicture: [],
				shelfRemark: '',
				shelfScore: null,
				monitoringScorePicture: [],
				monitoringScore: null,
				monitoringRemark: '',
				value: null,
				timeMode: '',
				concealedList: [],
				isBtnShow: true,
				// 提交的节流控制阀门
				timer: '',
				flag: 0, // 每步是否合格
			}
		},
		computed: {
			disable() {
				return this.evaluateId ? true : false
			}
		},
		onShow() {},
		onLoad(option) {
			console.log(option.isEchoNewMsg, '000000000000000000 ')
			this.taskId = option.assignTaskId
			// 通过任务id查询验收任务信息列表
			this.getEvaluateList()
			// 获取隐蔽模块
			this.getConcealedList()
			// 拿到固定表单值
			this.getTaskDetailByAssignTaskId()
			if (option.evaluateId) {
				this.evaluateId = option.evaluateId
				// 回显处理
				this.getEvaluateByEvaluateId()
				return
			}
			if (option.isEchoNewMsg == "true") {
				this.isEchoNewMsg = true
				// 获取最新的验收记录
				this.getEvaluateByTasKId()
			}
		},
		components: {
			// tabbar,
			signtrue,
			upload
		},
		methods: {
			
			showNowFinishi(item){
				 return this.$u.toast(`任务${item.isFinish}!`)
			},
			/**
			 * 方法说明
			 * author: iceyhu
			 * description: 监理验收时每步提交是否合格
			 * @param {Boolean} flag
			 * @return 
			 * @createTime: 2025-07-25 11:51:21
			 */
			// /evaluate/addEvaluate
			// submitFlag(flag) {
			// 	uni.$u.http.post('/evaluate/addEvaluate', {flag}).then(res => {
			// 		console.log('res: ',res);
			// 	} )
			// },
			/**
			 * 零食很忙第二步 监理验收直接去签名
			 * author: iceyhu
			 * description: 
			 * @param 
			 * @return 
			 * @createTime: 2025-07-03 16:39:04
			 */
			skipStep() {
				this.concealedList[this.concealedList.length - 1].flag = 1
				console.log('下一步', this.concealedList);
				
				const isImgNull =   this.concealedList.some((item) =>{
					
				    return   item.isFinish === '已完成' && !item.concealedScorePicture.length
				})
				if(isImgNull){
					return this.$u.toast('请上传验收图片!')
				}
				const isFlagNull =   this.concealedList.some((item) =>{
				    return  item.isFinish === '已完成' && !item.flag
				})
				if(isFlagNull){
					return this.$u.toast('请选择是否合格!')
				}
				const isNext =   this.concealedList.some((item) =>{
				    return  item.isFinish === '已完成' && item.flag === 2 && !item.concealedRemark
				})
				if(isNext){
					this.$u.toast('请输入不合格的备注!')
					return ''
				}else{
					if (this.brandPartyId !== 1  && this.brandPartyId !== 3) {
						this.current = 2
					} else {
						this.current = 4
					}	
				}
			
				
			},
			/** 零食很忙签名跳转到第二步
			 * 方法说明
			 * author: iceyhu
			 * description: 
			 * @param 
			 * @return 
			 * @createTime: 2025-07-03 17:33:34
			 */
			backStep() {
				if (this.brandPartyId !== 1 && this.brandPartyId !== 3) {
					this.current = 3
				} else {
					this.current = 1
				}
			},
			async updateConfirm() {
				
				console.log("最终提交的数据1",this.concealedList);
				this.finallyConcealedEvaluateList = []
				this.unfinished = false //是否有未完成
				if(!this.isEchoNewMsg){
					// 代表首次验收，之前没有验收记录
					this.concealedList.forEach(item =>{
						if(item.isFinish === '已完成' ||item.concealedScorePicture.length){
							this.finallyConcealedEvaluateList.push(item)
						}else {
							this.unfinished  = true
						}
					})
				}else{
					// 不是首次验收 之前可能存在验收记录  所以最终提交的数据要把两个数组合并且去重
					this.concealedEvaluateList.forEach(item =>{
						if(item.isFinish === '已完成' ||item.concealedScorePicture.length){
							this.finallyConcealedEvaluateList.push(item)
						}else {
							this.unfinished = true
						}
					})
					// 还需要合并concealedList 里面isShow !== 1 不等于1的
					this.concealedList.forEach(items =>{
						if(items.isShow !== 1 && items.isFinish === '已完成'){
							this.finallyConcealedEvaluateList.push(items)
						}else if(items.isShow !== 1 && items.isFinish != '已完成'){
							this.unfinished = true
						}
					})
					// 去除重复的
					
					this.finallyConcealedEvaluateList = [...new Map(this.finallyConcealedEvaluateList.map(item => [item.miniTaskId, item])).values()];
				}
				console.log("最终提交的数据2",this.finallyConcealedEvaluateList);
			
				const isUnqualified =   this.concealedList.some((item) =>{
					
				    return  item.flag === 2
				})
				console.log('isUnqualified',isUnqualified);
				console.log('unfinished',this.unfinished );
				if(isUnqualified){
					// 只有存在不合格 就不调用update
					 await this.addEvaluate(0)
				}else{
					// 判断是否有未完成的，有的话就不调用/assign/updateConfirm 这个接口
					if(this.unfinished){
						await this.addEvaluate(0)	
					}else{
						await this.addEvaluate(1)	
					}
					
				}
				
				// uni.$u.http.get('/assign/updateConfirm', {
				// 	params: {
				// 		assignTaskId: this.taskId
				// 	}
				// }).then(res => {
				// 	if (res) {
				// 		uni.showToast({
				// 			title: '验收成功!',
				// 			duration: 2000
				// 		})
				// 	}
				// }).then(res => {
				// 	this.addEvaluate(0)
				// })

			},
			getTaskDetailByAssignTaskId() {
				uni.$u.http.get('/task/getTaskDetailByAssignTaskId', {
					params: {
						assignTaskId: this.taskId,
					}
				}).then(res => {
					// console.log(res, '获取任务详情信息')
					if (res) {
						this.formData.endTime = res.endTime
						this.formData.assignName = res.assignName
						this.formData.projectUserName = res.projectUserName
						this.formData.userName = res.userName
						this.formData.companyName = res.companyName
						this.formData.chargeUserName = res.chargeUserName
						this.formData.afterName = res.afterName
					}
				})
			},
			// 解决按钮层级问题
			changeTimeFn() {
				setTimeout(() => {
					console.log('changeTimeFn')
					this.isBtnShow = true
				}, 200)
			},
			showTimePickerFn() {
				setTimeout(() => {
					console.log('showTimePickerFn')
					this.isBtnShow = false
				}, 100)
			},
			maskClick() {
				this.isBtnShow = true
				setTimeout(() => {
					console.log('maskClick')
					this.isBtnShow = true
				}, 200)
			},
			getConcealedList() {
				uni.$u.http.get(`/concealed/getConcealedList?assignTaskId=${this.taskId}`).then(res => {
					if (res) {
						console.log(res, '获取隐蔽模块')
						
						this.concealedList = res
						this.concealedList.map((item, index) => {
							if(!item.concealedRemark){
								item.concealedRemark = ''
							}
							if(item.concealedScorePicture){
								item.concealedScorePicture =item.concealedScorePicture.split(",")
							}else{
								item.concealedScorePicture = []
							}
							if(item.type === 1){
								// 装修 且用status判断
								if(item.status === 8 ){
									// item.isFinish = true
									item.isFinish = '已完成'
								}else if(item.status < 8){
									// item.isFinish = false
									item.isFinish = '未完成'
								}else if(item.status > 8){
									// 是否已验收 验收了就不让重复验收了
									item.isFinish = '已验收'
								}
							
							}else{
								// 除了装修以外的5个流程
								if(item.supplierState === 6 ){
									item.isFinish = '已完成'
								}else if(item.supplierState < 6){
									item.isFinish = '未完成'
								}else if(item.supplierState > 6){
									item.isFinish = '已验收'
								}
							}
							
							console.log(item.concealedName, '111')
							// this.$set(this.concealedEvaluateList, index, {
							// 	taskId: this.taskId,
							// 	concealedRemark: '',
							// 	type:item.type,
							// 	isFinish:item.isFinish,
							// 	miniTaskId:item.miniTaskId,
							// 	concealedScore: null,
							// 	concealedScorePicture: [],
							// 	concealedName: item.concealedName,
							// 	// images:item.images && item.images.length ? item.images : []
							// })
						})
						// console.log('任务数组',);
					}

				})
			},
			getEvaluateByEvaluateId() {
				uni.$u.http.get('/evaluate/getEvaluateByEvaluateId', {
					params: {
						evaluateId: this.evaluateId
					}
				}).then(res => {
					if (res) {
						console.log(res, '回显处理')
						this.formData.decorationStartDate = res.decorationStartDate
						this.formData.shelfDeliveryDate = res.shelfDeliveryDate
						this.supervisionScore = res.supervisionScore
						this.taskListEvaluationForm = res.taskListEvaluationList
						this.shelfScorePicture = res.shelfScorePicture,
							this.shelfRemark = res.shelfRemark,
							this.shelfScore = res.shelfScore,
							this.monitoringScorePicture = res.monitoringScorePicture,
							this.monitoringScore = res.monitoringScore,
							this.monitoringRemark = res.monitoringRemark,
							this.remark = res.remark,
							this.franchiseScore = res.franchiseScore,
							this.picture = res.picture
						this.concealedEvaluateList = res.concealedEvaluateList
					}

				})
			},
			getEvaluateByTasKId() {
				uni.$u.http.get('/evaluate/getEvaluateByTasKId', {
					params: {
						taskId: this.taskId
					}
				}).then(res => {
					if (res) {
						console.log(res, '获取最新的验收记录')
						this.formData.decorationStartDate = res.decorationStartDate
						this.formData.shelfDeliveryDate = res.shelfDeliveryDate
						this.supervisionScore = res.supervisionScore
						this.taskListEvaluationForm = res.taskListEvaluationList
						this.shelfScorePicture = res.shelfScorePicture,
							this.shelfRemark = res.shelfRemark,
							this.shelfScore = res.shelfScore,
							this.monitoringScorePicture = res.monitoringScorePicture,
							this.monitoringScore = res.monitoringScore,
							this.monitoringRemark = res.monitoringRemark,
							this.remark = res.remark,
							this.franchiseScore = res.franchiseScore
						if (res.concealedEvaluateList.length != 0) {
							this.concealedEvaluateList = res.concealedEvaluateList
						}
					}
				})
			},
			uploadFileConcealed(msg) {
				this.concealedList[msg.name].concealedScorePicture = msg.files
			},
			uploadFileMonitor(msg) {
				this.monitoringScorePicture = msg.files
			},
			uploadFileShelf(msg) {
				this.shelfScorePicture = msg.files
			},
			uploadFileFn(msg) {
				this.taskListEvaluationForm[msg.name].picture = msg.files
			},
			getKey(index, index1) {
				if (index + 1 > this.day) {
					this.day = index + 1
					return index1 + 1 + this.index
				} else {
					this.index = index + 1
					return this.index + index1 + 1
				}
			},
			handlerTime(mode) {
				if (this.disable) return
				this.show = true
				this.timeMode = mode
			},
			confirmTime(time) {
				this.formData[this.timeMode] = time[0]
				this.show = false
			},
			getEvaluateList() {
				uni.$u.http.get('/evaluate/getTaskListTDetailsListByTaskId', {
					params: {
						taskId: this.taskId
					}
				}).then(res => {
					if (res) {
						console.log(res, '通过任务id查询验收任务信息列表')
						this.evaluateList = JSON.parse(res)
						let key = 0
						this.evaluateList.forEach((obj, index) => {
							if (obj.task && obj.task.length > 0) {
								obj.task.forEach((obj_sub, index_sub) => {
									obj_sub.index = key
									this.$set(this.taskListEvaluationForm, key, {
										taskDetail: obj.name + ':' + obj_sub.taskName,
										picture: [],
										remark: ""
									});
									key++
								})
							}

						})
					}

				})
			},
			getSignImg(e) {
				console.log(e)
				this.picture = e.base64
			},
			// change(e) {
			//       console.log("e:", e);
			// 	  this.flag = e
			//     },
			verityScore(score) {
				let num = Number(score)
				if (num < 0 || num > 100) {
					return false
				}
				return true
			},
			verityValue() {
				let result = true
				for (let score in this.franchiseScore) {
					if (this.franchiseScore[score] && !this.verityScore(this.franchiseScore[score])) {
						result = false
					}
				}
				if (!result) return result
				this.concealedEvaluateList.map(item => {
					if (item.concealedScore && !this.verityScore(item.concealedScore)) {
						result = false
					}
				})
				if (!result) return result

				if (this.monitoringScore && !this.verityScore(this.monitoringScore)) result = false
				if (this.shelfScore && !this.verityScore(this.shelfScore)) result = false
				if (this.supervisionScore && !this.verityScore(this.supervisionScore)) result = false
				return result
			},
			addEvaluate(isOk) {
				if (!this.picture) {
					return uni.$u.toast('请填写签名!');
				}
				if (!this.verityValue()) {
					return uni.$u.toast('评分不能低于0高于100!');
				}
				if (this.flag == 1) {
					return uni.showLoading({
						title: '请勿重复提交 :)'
					});
				}
				if (this.timer) {
					return uni.$u.toast('提交太频繁了!');
				}
				this.timer = setTimeout(() => {
					this.timer = null
				}, 3000)
				this.flag = 1
				const finallyConcealedEvaluateList = []
				const params = {
					...this.formData,
					taskId: this.taskId,
					taskListEvaluationList: Object.values(this.taskListEvaluationForm),
					franchiseScore: this.franchiseScore,
					monitoringRemark: this.monitoringRemark,
					monitoringScore: this.monitoringScore,
					monitoringScorePicture: this.monitoringScorePicture,
					shelfRemark: this.shelfRemark,
					shelfScore: this.shelfScore,
					shelfScorePicture: this.shelfScorePicture,
					supervisionScore: this.supervisionScore,
					remark: this.remark,
					picture: this.picture,
					concealedEvaluateList: this.finallyConcealedEvaluateList
				}
			
				uni.$u.http.post('/evaluate/addEvaluate', params).then(res => {
					console.log(res, '添加验收记录成功')
					this.flag = 0
					if (res) {
						if (isOk == 1) {
							// 全部合格才调用下面这个接口(且不能有未完成的)  否则不需要调
							uni.$u.http.get('/assign/updateConfirm', {
								params: {
									assignTaskId: this.taskId
								}
							}).then(res => {
								if (res) {
									uni.showToast({
										title: '验收成功!',
										duration: 2000
									})

									setTimeout(() => {
										uni.navigateBack({
											delta: 1
										});
									}, 1000)
								}
							})
						} else {
							uni.showToast({
								title: '保存成功!',
								duration: 2000
							})

							setTimeout(() => {
								uni.navigateBack({
									delta: 1
								});
							}, 1000)
						}

					} else {
						uni.showToast({
							title: '保存失败',
							duration: 2000
						})
					}
				})
			}

		}
	}
</script>
<style lang="scss" scoped>
	.custom-style {
		color: #ff0000;
		width: 400rpx;
	}
	/deep/.container {
		.u-textarea {
			background-color: unset !important;
		}

		.uni-date-x--border {
			border: unset;

		}

		.uni-datetime-picker--btn {
			background-color: #13989a;
		}

		.u-border {
			background-color: unset !important;
		}

		// .uni-date-changed{
		// 	position: absolute;
		// 	bottom: 0;
		// 	left: 0;
		// 	right: 0;
		// 	z-index: 55;
		// }
		.dialog-close {
			display: none;
		}
	}

	.container_h1 {
		padding-bottom: 200rpx !important;
	}

	.container_h2 {
		padding-bottom: 200rpx !important;
	}

	.label_1 {
		width: 300rpx !important;
	}

	.tack_item_0 {
		margin-top: unset !important;
		border-top: unset !important;
	}

	.input_item {
		display: flex;
		padding-bottom: 20rpx;
	}

	.tack_item {
		border-top: 1px solid #ebedf0;
		margin-top: 10rpx;
		padding: 20rpx 0;
	}

	.val_1 {
		width: auto !important;
	}

	.container {
		width: 660rpx;
		padding: 20rpx;
		padding-top: 0;
		position: absolute;
		left: 25rpx;
		top: 400rpx;
		z-index: 1;
		background-color: white;
		border: 1rpx solid #eee;
		border-radius: 10rpx;
		background-image: url('https://renovationcdn.jiachuangnet.com/addMaterial/topBg.png');
		background-size: 100%, auto;
		background-repeat: no-repeat;
	}

	.container>view>view {
		padding: 20rpx;
		border-bottom: 1rpx solid #eee;
	}

	.container>view>view:nth-last-child(1) {
		border-bottom: none !important;
	}

	.item {
		height: 294rpx;
		width: 700rpx;
		margin-bottom: 20rpx;
		// background-size: 100% 100%;
		// background: url('http://skv5jh74d.hn-bkt.clouddn.com/addMaterial/itemBg.png?e=1728810230&token=Uw65xcftwz9gmAL88CkCQDOLnHuqiD5jAvGQ7msg:wczllfps1gJQtgAUO0-qNJnVuYU=');
	}

	.topItem {
		height: 394rpx;
		width: 700rpx;

		margin-bottom: 20rpx;
	}

	.shopSelect {
		width: calc(100% - 40rpx);
		padding: 20rpx;
		font-size: 32rpx;
		color: white;
	}

	.name {
		padding: 30rpx 20rpx;
		font-size: 30rpx;
		color: #1E272E;
	}

	.unit {
		background-color: #F3F5F9;
		width: calc(100% - 80rpx);
		border-radius: 10rpx;
		margin: 0 auto;
		height: 115rpx;
		padding: 0 20rpx;
	}

	.unitKey {
		color: #8A8A8A;
		font-size: 28rpx;
		text-align: center;
	}

	.unitValue {
		color: #1E272E;
		text-align: center;
		font-size: 28rpx;
		margin-top: 10rpx;
	}

	.bottom {
		position: fixed;
		bottom: 0;
		left: 0;
		background-color: white;
		z-index: 2 !important;
		width: 100vw;
		box-sizing: border-box;
		padding: 20rpx;
		min-height: 20rpx;
	}

	.bottomleft {
		height: 88rpx;
		width: 250rpx;
		border-bottom-left-radius: 80rpx;
		border-top-left-radius: 80rpx;
		background-color: #222426;
		color: white;
		font-size: 24rpx;
		text-align: center;
		line-height: 88rpx;
	}

	.bottomright {
		width: 450rpx;
		height: 88rpx;
		border-bottom-right-radius: 80rpx;
		border-top-right-radius: 80rpx;
		background-color: #13989A;
		color: white;
		font-size: 30rpx;
		text-align: center;
		line-height: 88rpx;
		;
	}

	.bottomright1 {
		margin-left: 20rpx;
		width: 400rpx;
		height: 88rpx;
		border-radius: 80rpx;
		background-color: #13989A;
		color: white;
		font-size: 30rpx;
		text-align: center;
		line-height: 88rpx;
		;
	}

	.container /deep/ .uni-select {
		border: none !important;
	}

	.container /deep/ .uni-select__input-placeholder {
		font-size: 28rpx !important;
		color: #c7ccd3;
	}

	.container /deep/ .uni-icons {
		font-size: 32rpx;
		margin-left: 10rpx;
	}

	.signtrue {
		width: 100%;
		height: 400rpx;
	}
</style>
<style>
	page {
		background-color: #f8f8f8;
	}
</style>